namespace Codeplus.Dhruvtaata.Web.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Addresses",
                c => new
                    {
                        AddressId = c.Int(nullable: false, identity: true),
                        HouseNo = c.String(),
                        Building = c.String(),
                        Locality = c.String(),
                        Landmark = c.String(),
                        City = c.String(),
                        State = c.String(),
                        Country = c.String(),
                    })
                .PrimaryKey(t => t.AddressId);
            
            CreateTable(
                "dbo.People",
                c => new
                    {
                        PersonId = c.Int(nullable: false, identity: true),
                        FirstName = c.String(),
                        LastName = c.String(),
                        DateOfBirth = c.DateTime(nullable: false),
                        EmailAddress = c.String(),
                        ContactPhone = c.String(),
                        ContactAddress_AddressId = c.Int(),
                    })
                .PrimaryKey(t => t.PersonId)
                .ForeignKey("dbo.Addresses", t => t.ContactAddress_AddressId)
                .Index(t => t.ContactAddress_AddressId);
            
            CreateTable(
                "dbo.Exams",
                c => new
                    {
                        ExamId = c.Int(nullable: false, identity: true),
                        ExamName = c.String(),
                        Subject = c.String(),
                        Category = c.String(),
                        Duration = c.Int(nullable: false),
                        NumberOfQuestions = c.Int(nullable: false),
                        ScheduledStart = c.DateTime(nullable: false),
                        NumberOfRetries = c.Int(nullable: false),
                        Level = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ExamId);
            
            CreateTable(
                "dbo.Questions",
                c => new
                    {
                        QuestionId = c.Int(nullable: false, identity: true),
                        Text = c.String(),
                        CorrectAnswer = c.Int(nullable: false),
                        Exam_ExamId = c.Int(),
                    })
                .PrimaryKey(t => t.QuestionId)
                .ForeignKey("dbo.Exams", t => t.Exam_ExamId)
                .Index(t => t.Exam_ExamId);
            
            CreateTable(
                "dbo.StudentResponses",
                c => new
                    {
                        StudentResponseId = c.Int(nullable: false, identity: true),
                        ResponseIndex = c.Int(nullable: false),
                        Exam_ExamId = c.Int(),
                        Question_QuestionId = c.Int(),
                    })
                .PrimaryKey(t => t.StudentResponseId)
                .ForeignKey("dbo.Exams", t => t.Exam_ExamId)
                .ForeignKey("dbo.Questions", t => t.Question_QuestionId)
                .Index(t => t.Exam_ExamId)
                .Index(t => t.Question_QuestionId);
            
            CreateTable(
                "dbo.Students",
                c => new
                    {
                        PersonId = c.Int(nullable: false),
                        College = c.String(),
                        ClassYear = c.String(),
                        Semester = c.String(),
                        Rating = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.PersonId)
                .ForeignKey("dbo.People", t => t.PersonId)
                .Index(t => t.PersonId);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.Students", new[] { "PersonId" });
            DropIndex("dbo.StudentResponses", new[] { "Question_QuestionId" });
            DropIndex("dbo.StudentResponses", new[] { "Exam_ExamId" });
            DropIndex("dbo.Questions", new[] { "Exam_ExamId" });
            DropIndex("dbo.People", new[] { "ContactAddress_AddressId" });
            DropForeignKey("dbo.Students", "PersonId", "dbo.People");
            DropForeignKey("dbo.StudentResponses", "Question_QuestionId", "dbo.Questions");
            DropForeignKey("dbo.StudentResponses", "Exam_ExamId", "dbo.Exams");
            DropForeignKey("dbo.Questions", "Exam_ExamId", "dbo.Exams");
            DropForeignKey("dbo.People", "ContactAddress_AddressId", "dbo.Addresses");
            DropTable("dbo.Students");
            DropTable("dbo.StudentResponses");
            DropTable("dbo.Questions");
            DropTable("dbo.Exams");
            DropTable("dbo.People");
            DropTable("dbo.Addresses");
        }
    }
}
